document.addEventListener('DOMContentLoaded', async () => {
    try {
        const response = await fetch('/demo.json');
        const newsData = await response.json();

        const testList = document.getElementById('list');
        newsData.forEach(article => {
            const articleElement = document.createElement('div');
            articleElement.innerHTML = `
                <h2>${article.title}</h2>
                <p>${article.content}</p>
            `;
            testList.appendChild(articleElement);
        });
    } catch (error) {
        console.error('获取数据失败', error);
    }

    if ('serviceWorker' in navigator) {
        navigator.serviceWorker.register('/sw.js')
            .then(registration => {
                console.log('注册成功', registration);
            })
            .catch(error => {
                console.error('注册失败', error);
            });
    }
});